package com;

import Sort_06.MergeSorting_07;
import Sort_06.QuickSort_06;
import Sort_06.ShellSorting_05;
import com.insertSort.InsertionSort;
import com.quickSort.QuickSort;
import com.quickSort.QuickSort3Way;
import com.selectionSort.SelectionSort;
import com.shellSort.ShellSort;
import com.shellSort.ShellSortEnhance;

import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class sortEfficiency {

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        int testSize = 10000000;
        Random random = new Random();
        Integer[] array = new Integer[testSize];
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(10000);
        }
        Integer[] arrayForShell = Arrays.copyOf(array, array.length);
        Integer[] arrayForInsertion = Arrays.copyOf(array, array.length);
        Integer[] arrayForSelection = Arrays.copyOf(array, array.length);
        Integer[] arrayForQuickSort = Arrays.copyOf(array, array.length);
        Integer[] arrayForQuickSort3Way = Arrays.copyOf(array, array.length);


        int[] arrayForMyShellSort = Arrays.stream(Arrays.copyOf(array, array.length)).mapToInt(Integer::valueOf).toArray();
        int[] arrayForMergeSort = Arrays.stream(Arrays.copyOf(array, array.length)).mapToInt(Integer::valueOf).toArray();
        int[] arrayForSystemMergeSort = Arrays.stream(Arrays.copyOf(array, array.length)).mapToInt(Integer::valueOf).toArray();
        int[] arrayForQuickSortGuiGu = Arrays.stream(Arrays.copyOf(array, array.length)).mapToInt(Integer::valueOf).toArray();
        int[] arrayForMergeSortGuiGu = Arrays.stream(Arrays.copyOf(array, array.length)).mapToInt(Integer::valueOf).toArray();


        boolean isShowSortResult = false;

        executorService.execute(() -> {
            TestTimer testTimer = new TestTimer();

            Sort<Integer> quickSort = new QuickSort3Way<>();//new InsertionSort<String>();//new SelectionSort<String>();
            quickSort.sort(arrayForQuickSort3Way);
            testTimer.end("三项切分的快速排序");

            if (isShowSortResult) {

                quickSort.show(arrayForQuickSort3Way);
            }
        });

        executorService.execute(() -> {
            TestTimer testTimer = new TestTimer();

            Sort<Integer> quickSort = new QuickSort<>();//new InsertionSort<String>();//new SelectionSort<String>();
            quickSort.sort(arrayForQuickSort);
            testTimer.end("快速排序");

            if (isShowSortResult) {

                quickSort.show(arrayForQuickSort);
            }
        });


        executorService.execute(() -> {
            TestTimer testTimer = new TestTimer();

            QuickSort_06.quickSort(arrayForQuickSortGuiGu, 0, arrayForMergeSort.length - 1);
            testTimer.end("尚硅谷版本的快速排序");
            if (isShowSortResult) {
                System.out.println(Arrays.toString(arrayForQuickSortGuiGu));
            }
        });

        executorService.execute(() -> {
            TestTimer testTimer = new TestTimer();

            MergeSorting_07.mergeSorting(arrayForMergeSortGuiGu, 0, arrayForMergeSortGuiGu.length - 1,new int[arrayForMergeSortGuiGu.length]);
            testTimer.end("尚硅谷版本的归并排序");
            if (isShowSortResult) {
                System.out.println(Arrays.toString(arrayForMergeSortGuiGu));
            }
        });

        executorService.execute(() -> {
            TestTimer testTimer = new TestTimer();

            MergeSorting_07.mergeSorting(arrayForMergeSort, 0, arrayForMergeSort.length - 1, new int[arrayForMergeSort.length]);
            testTimer.end("归并排序");
            if (isShowSortResult) {
                System.out.println(Arrays.toString(arrayForMergeSort));
            }
        });

        executorService.execute(() -> {
            TestTimer testTimer = new TestTimer();

            Arrays.sort(arrayForSystemMergeSort);
            testTimer.end("系统的归并排序");
            if (isShowSortResult) {
                System.out.println(Arrays.toString(arrayForSystemMergeSort));
            }
        });

//        executorService.execute(() -> {
//            Sort<Integer> shellSort = new ShellSortEnhance<>();//new InsertionSort<String>();//new SelectionSort<String>();
//            shellSort.sort(arrayForShell);
//            testTimer.end("希尔排序");
//            if (isShowSortResult) {
//
//                shellSort.show(arrayForShell);
//            }
//        });

        /*executorService.execute(() -> {
            ShellSorting_05.shellSorting(arrayForMyShellSort);
            testTimer.end("我的希尔排序");
            if (isShowSortResult) {
                System.out.println(Arrays.toString(arrayForMyShellSort));

            }
        });

        executorService.execute(() -> {
            Sort<Integer> shellSort = new InsertionSort<>();//new InsertionSort<String>();//new SelectionSort<String>();
            shellSort.sort(arrayForInsertion);
            testTimer.end("插入排序");
            if (isShowSortResult) {

                shellSort.show(arrayForInsertion);
            }
        });

        executorService.execute(() -> {
            Sort<Integer> shellSort = new SelectionSort<>();//new InsertionSort<String>();//new SelectionSort<String>();
            shellSort.sort(arrayForSelection);
            testTimer.end("选择排序");
            if (isShowSortResult) {

                shellSort.show(arrayForSelection);
            }
        });*/

        executorService.shutdown();
    }

}
